package cn.ycms.jdbc.support;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.ycms.jdbc.RowMapper;



public class HashMapsMapper implements RowMapper<List<Map<String, String>>> {

	public List<Map<String, String>> mapper(ResultSet rs) throws SQLException {
		ResultSetMetaData rmd = rs.getMetaData();
		int count = rmd.getColumnCount();
		String[] columns = new String[count];
		for (int i = 0; i < count; i++) {
			columns[i] = rmd.getColumnName(i + 1);
		}
		List<Map<String, String>> datas = new ArrayList<Map<String, String>>();
		while (rs.next()) {
			Map<String, String> data = new HashMap<String, String>();
			for (int i = 0; i < count; i++) {
				data.put(columns[i], rs.getString(columns[i]));
			}
			datas.add(data);
		}
		return datas;
	}

}
